<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #img{
            /* 兼容 */
            opacity: .3;filter: alpha(opacity=30);
            display: block;width: 500px;height: 500px;margin: 0 auto;
        }
    </style>
</head>
<body>
    <!-- <img src="https://p1.ssl.qhimgs1.com/sdr/400__/t014ac0300423ca4ee1.png" alt="" id="img"> -->
    <img src="http://5b0988e595225.cdn.sohucs.com/images/20181225/b4bad1eefe5a4f5494ce607ab525ca30.gif" alt="" id="img">
</body>
<script>
    var oimg=document.getElementById("img")
    oimg.onmouseover=function(){
        move(100);
    }

    oimg.onmouseout=function(){
        move(30);
    }
    var alpha=30;
    var timer=null;
    function move(Target){
        var speed=2;
        clearInterval(timer)
        speed=Target>alpha?Math.abs(speed):-Math.abs(speed);

        timer=setInterval(function(){
            if(Target==alpha){
                clearInterval(timer);
            }else{
                alpha+=speed
            }
            oimg.style.opacity=alpha/100;
            oimg.style.filter=`alpha(opacity=${alpha})`;
        },30)
    }
</script>
</html>